//
//  ReportViewController.m
//  TT
//
//  Created by lanou3g on 16/3/15.
//  Copyright © 2016年 Super磊. All rights reserved.
//

#import "ReportViewController.h"
#import "customReasonViewController.h"

@interface ReportViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableV;
@property(nonatomic, strong)NSMutableArray *reasonArray;
@property(nonatomic, strong)NSMutableArray *markArray;
@end

@implementation ReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cancel_31.929203539823px_1143862_easyicon.net.png"] style:(UIBarButtonItemStyleDone) target:self action:@selector(leftAction)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"举报" style:(UIBarButtonItemStyleDone) target:self action:@selector(rightAction)];
    self.tableV = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:(UITableViewStylePlain)];
    [self.view addSubview:self.tableV];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    [self setHeadView];
}

- (void)setHeadView {
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
    self.tableV.tableHeaderView = lable;
}
- (void)leftAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)rightAction {
    UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"谢谢" message:@"TT已经收到你的举报了" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"好" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    [alertC addAction:ok];
    [self presentViewController:alertC animated:YES completion:nil];
}
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.reasonArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"first_cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"first_cell"];
    }
    if (indexPath.row == self.reasonArray.count - 1) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    cell.textLabel.text = self.reasonArray[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == self.reasonArray.count - 1) {
        customReasonViewController *customRVC = [[customReasonViewController alloc] init];
//        UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:customRVC];
//        [self presentViewController:na animated:YES completion:nil];
        [self.navigationController pushViewController:customRVC animated:YES];
    } else {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if ([self.markArray containsObject:@(indexPath.row)]) {
            [self.markArray removeObject:@(indexPath.row)];
            cell.accessoryType = UITableViewCellAccessoryNone;
        } else {
            [self.markArray addObject:@(indexPath.row)];
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
        }
    }
    
}
- (NSMutableArray *)markArray {
    if (!_markArray) {
        _markArray = [NSMutableArray array];
    }
    return _markArray;
}

- (NSMutableArray *)reasonArray {
    if (!_reasonArray) {
        _reasonArray = [NSMutableArray arrayWithObjects:@"头像、资料作假",@"骚扰广告",@"诈骗/托",@"色情低俗",@"恶意骚扰、不文明语言",@"其他", nil];
    }
    return _reasonArray;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
